//
//  ChangeNowPasswordViewController.m
//  cityStar
//
//  Created by joyban on 14-12-27.
//  Copyright (c) 2014年 tiny. All rights reserved.
//

#import "ChangeNowPasswordViewController.h"
#import "UIColor+FlatUI.h"
#import "FindNowPassWordViewController.h"

@interface ChangeNowPasswordViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *NewNowPassward;
@property (weak, nonatomic) IBOutlet UITextField *OldNowPassward;
@property (weak, nonatomic) IBOutlet UITextField *SecenNewPassword;
@property (weak, nonatomic) IBOutlet UIButton *quedinBtn;
@property (strong, nonatomic)  UILabel *label;


@end

@implementation ChangeNowPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"";
    [self addBackButton];
    __weak typeof(self)weakSelf = self;
    [self addRightButtonWithTitle:@"找回密码" actionBlock:^{
        [weakSelf.label removeFromSuperview];
        FindNowPassWordViewController *finNowPassWord = [[FindNowPassWordViewController alloc]init];
        [weakSelf.navigationController pushViewController:finNowPassWord animated:YES];
    }];
    
    self.quedinBtn.layer.cornerRadius = 4;
    self.OldNowPassward.placeholder = @"请输入原提现密码";
    self.NewNowPassward.placeholder = @"请输入新提现密码";
    self.SecenNewPassword.placeholder = @"请重复输入新提现密码";
    
    self.OldNowPassward.returnKeyType = UIReturnKeyDone;
    self.OldNowPassward.delegate = self;
    self.NewNowPassward.returnKeyType = UIReturnKeyDone;
    self.NewNowPassward.delegate = self;
    self.SecenNewPassword.returnKeyType = UIReturnKeyDone;
    self.SecenNewPassword.delegate = self;
}

-(void)viewWillAppear:(BOOL)animated
{
    self.label = [[UILabel alloc]initWithFrame:CGRectMake(100, 32, 120, 20)];
    self.label.font = [UIFont boldSystemFontOfSize:18];
    self.label.textAlignment = NSTextAlignmentCenter;
    self.label.text = @"修改提现密码";
    self.label.textColor = [UIColor colorFromHexCode:@"585858"];
    [self.navigationController.view addSubview:self.label];
}

-(void)back
{
    [self.label removeFromSuperview];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)addRightButtonWithTitle:(NSString *)title actionBlock:(void(^)(void))block
{
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setFrame:CGRectMake(0, 0, 65, 20)];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightButton setTitle:title forState:UIControlStateNormal];
    [rightButton setTitleColor:[UIColor colorWithRed:0.991 green:0.532 blue:0.303 alpha:1.000] forState:UIControlStateHighlighted];
    [rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(rightBar_Touched:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.rightBarActionBlock = block;
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


#pragma - mark textDeletage

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    return YES;
}

- (IBAction)didRetun_Action:(id)sender
{
    if([self.OldNowPassward.text isEqualToString:@""])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"原密码不能为空" delegate:self cancelButtonTitle:@"确认" otherButtonTitles: nil];
        [alert show];
    }else if([self.NewNowPassward.text isEqualToString:@""])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"新密码不能为空" delegate:self cancelButtonTitle:@"确认" otherButtonTitles: nil];
        [alert show];
    }else if ([self.SecenNewPassword.text isEqualToString:@""])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"再一次输入新密码不能为空" delegate:self cancelButtonTitle:@"确认" otherButtonTitles: nil];
        [alert show];
    }else if(![self.NewNowPassward.text isEqualToString: self.SecenNewPassword.text])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"两次新密码不一致空" delegate:self cancelButtonTitle:@"确认" otherButtonTitles: nil];
        [alert show];
    }else{
        
    }
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.OldNowPassward resignFirstResponder];
    [self.NewNowPassward resignFirstResponder];
    [self.SecenNewPassword resignFirstResponder];
}

/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
